//
//  BNHomeListCell.m
//  BeautifulNote
//
//  Created by Apple on 2019/7/16.
//  Copyright © 2019 Maker. All rights reserved.
//

#import "BNHomeListCell.h"
#import <YYImage.h>

@interface BNHomeListCell ()

@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *contentLb;
@property (nonatomic, strong) YYAnimatedImageView *weatherIV;

@end

@implementation BNHomeListCell

#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self addWeatherIV];
        [self addTimeLb];
        [self addContentLb];
        self.timeLb.text = @"11 / 04";
        self.contentLb.text = @"北岛的这首《波兰来客》写出了很多人的心声，处于生活的奔忙之中，很久没见的朋友，很久没触摸的吉他，很久没翻过的书，还有很多很多“很久没去回忆或没来得及整理”的往事，我们有太多的内心情绪和故事需要梳理，但是残酷的现实重压让我们喘不过气来，我们几乎忘记了自己是谁？生于这个世界是为了什么？活了半辈子，自己究竟要做什么，究竟要的是什么";
        
        self.weatherIV.image = [YYImage imageNamed:@"snow.gif"];
        self.contentLb.textColor = orangeMood;

        self.contentView.layer.cornerRadius = 6;
        self.contentView.layer.masksToBounds = YES;
    }
    return self;
}

#pragma mark - private method
- (void)addTimeLb {
    _timeLb = [UILabel new];
    _timeLb.font = mediumFont(30);
    _timeLb.textColor = bnColor(38, 209, 221);
    _timeLb.numberOfLines = 2;
    _timeLb.textAlignment = NSTextAlignmentCenter;
    
    [self.contentView addSubview:_timeLb];
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(20);
    }];
}

- (void)addContentLb {
    _contentLb = [UILabel new];
    _contentLb.font = lightFont(16);
    _contentLb.textColor = [UIColor whiteColor];
    _contentLb.numberOfLines = 0;
    
    [self.contentView addSubview:_contentLb];
    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(self->_timeLb.mas_bottom).mas_equalTo(20);
        make.bottom.mas_equalTo(-20);
    }];
}

- (void)addWeatherIV {
    _weatherIV = [YYAnimatedImageView new];
    _weatherIV.contentMode = UIViewContentModeScaleAspectFill;
    
    [self.contentView addSubview:_weatherIV];
    [_weatherIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

#pragma mark - getter & setter
- (void)setModel:(BNHomeModel *)model {
    
    self.timeLb.text = [NSString stringWithFormat:@"%@ / %@", model.day, model.month];
    self.contentLb.text = model.content;
    
    switch (model.weather) {
        case BNWeatherTypeSunny:
            self.weatherIV.image = [YYImage imageNamed:@"sunny.gif"];
            break;
        case BNWeatherTypeRain:
            self.weatherIV.image = [YYImage imageNamed:@"rain.gif"];
            break;
        case BNWeatherTypeWindy:
            self.weatherIV.image = [YYImage imageNamed:@"windy.gif"];
            break;
        case BNWeatherTypeSnow:
            self.weatherIV.image = [YYImage imageNamed:@"snow.gif"];
            break;
        default:
            break;
    }
  
    switch (model.mood) {
        case BNMoodTypeRed:
            self.contentLb.textColor = redMood;
            break;
        case BNMoodTypeOrange:
            self.contentLb.textColor = orangeMood;
            break;
        case BNMoodTypeYellow:
            self.contentLb.textColor = yellowMood;
            break;
        case BNMoodTypeGreen:
            self.contentLb.textColor = greenMood;
            break;
        case BNMoodTypeQingse:
            self.contentLb.textColor = qingseMood;
            break;
        case BNMoodTypeBlue:
            self.contentLb.textColor = blueMood;
            break;
        case BNMoodTypePurple:
            self.contentLb.textColor = purpleMood;
            break;
        case BNMoodTypeWhite:
            self.contentLb.textColor = whiteMood;
            break;
        case BNMoodTypeGray:
            self.contentLb.textColor = greenMood;
            break;
        case BNMoodTypeBlack:
            self.contentLb.textColor = blackMood;
            break;
        default:
            self.contentLb.textColor = whiteMood;
            break;
    }
}

@end
